<template>
  <div class="layout-container" @click="handleLayoutClick">
    <header class="header">
      <div class="header-left">
        <img 
          src="../assets/1.svg" 
          class="avatar" 
          @click.stop="toggleSideMenu"
        />
        <h1 class="title">Delegation List</h1>
      </div>
      <div class="header-right">
        <button class="menu-button">≡</button>
      </div>
    </header>

    <main class="main-content">
      <slot></slot>
    </main>

    <Transition name="slide">
      <SideMenu v-if="isMenuOpen" />
    </Transition>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import SideMenu from '../components/SideMenu.vue'

const isMenuOpen = ref(false)
const userAvatar = ref('../assets/1.svg')

const toggleSideMenu = () => {
  isMenuOpen.value = !isMenuOpen.value
}

const handleLayoutClick = (event) => {
  if (isMenuOpen.value) {
    isMenuOpen.value = false
  }
}
</script>

<style scoped>
.layout-container {
  height: 100%;
  position: relative;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  background: white;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
}

.title {
  font-size: 1.2rem;
  font-weight: 500;
  color: black;
}

.main-content {
  height: calc(100vh - 72px);
  overflow-y: auto;
}

.slide-enter-active,
.slide-leave-active {
  transition: transform 0.3s ease;
}

.slide-enter-from,
.slide-leave-to {
  transform: translateX(-100%);
}
</style>